package com.newer.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newer.domain.DeliveryOrder;
import com.newer.domain.Material;
import com.newer.domain.Supplier;
import com.newer.dto.DeliveryOrderDto;
import com.newer.dto.LoginDto;
import com.newer.service.ClientOrderService;
import com.newer.service.DeliveryOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Deliveryorder")
public class UserController {
    @Autowired
    private DeliveryOrderService deliveryOrderService;

    //查询
    @RequestMapping("selectDeliveryorder")
    public Page selectDeliveryorder(int page, int size, String deliveryId, Model model) {

        Page page1 = new Page();

        page1.setSize(size);
        page1.setCurrent(page);


        Page<DeliveryOrder> deliveryOrder = this.deliveryOrderService.selectdeliveryorder(page1, deliveryId);

        System.out.println(deliveryOrder.getSize());
        System.out.println(deliveryOrder.getPages());
        System.out.println(deliveryOrder.getCurrent());
        if (deliveryOrder != null) {
            model.addAttribute("deliveryOrder", deliveryOrder);
            return deliveryOrder;
        }
        return deliveryOrder;
    }

    @RequestMapping("InsertDeliveryorder")
    public boolean InsertDeliveryorder(@RequestBody DeliveryOrder deliveryOrder) {

        return this.deliveryOrderService.save(deliveryOrder);
    }

    @RequestMapping("updateDeliveryorder")
    public Boolean updateDeliveryorder(String deliveryid) {
        System.out.println(deliveryid);
        DeliveryOrder deliveryOrder=new DeliveryOrder();
        deliveryOrder.setState("已出库");
        deliveryOrder.setDeliveryid(deliveryid);
        return this.deliveryOrderService.updateById(deliveryOrder);


    }

}
